<?php

function smarty_function_get_gid_by_uid($params, &$smarty) {
    //Get value from page
    $uid = $params['uid'];
    if($uid){
      //Query data

      //Check exist user & topic
      $pntables = pnDBGetTables();
      $table  = $pntables['group_membership'];
      $column = $pntables['group_membership_column'];

      $sql = "SELECT
                $table.$column[gid]  
              FROM
                $table 
              WHERE
                $table.$column[uid] = ".$uid;

      $column = array("gid");
      $result = DBUtil::executeSQL($sql);
      $objectArray = DBUtil::marshallObjects ($result, $column);
      $gid = $objectArray['0']['gid'];
    } else {
        $smarty->assign('gid', 0);
    }    
    
    if ($gid) {
        $smarty->assign('gid', $gid); 
    } else {
        $smarty->assign('gid', 0);
    }
}